package info.tsukaworld.actor.mob.pathfinding;

import info.tsukaworld.grid.Location;

public class SimpleHeuristicCalculator
{
    public final int obstacle;

    public SimpleHeuristicCalculator(final int area)
    {
        obstacle = area + 1;
    }

    public int calculateHeuristic(final Tile startTile,
                                  final Tile endTile)
    {
        final int distance;

        if(startTile.getObstacle() != null)
        {
            distance = obstacle;
        }
        else
        {
            final Location startLoc;
            final Location endLoc;
            final int      rows;
            final int      cols;

            startLoc = startTile.getLocation();
            endLoc   = endTile.getLocation();
            rows     = Math.abs(startLoc.getRow() - endLoc.getRow());
            cols     = Math.abs(startLoc.getCol() - endLoc.getCol());

            if(rows > cols)
            {
                distance = cols + (rows - cols);
            }
            else
            {
                distance = rows + (cols - rows);
            }
        }

        return (distance);
    }
}